<template>
<div class="login-box" v-loading.body="Loading">
  <div class="login" v-if="!Loading">
    <div class="logo">
      <span class="name">AFLY-运营商管理系统</span>
    </div>
    <div class="loginName">登录</div>
    <div class="login-from">
      <div class="input">
        <label class="label" @click="inputFocus('phone')" :class="{isFocus: isFocusPhone || loginForm.username}">帐号</label>
        <input type="text" ref="focusPhone"  v-model="loginForm.username" @keyup.13="submitLogin" maxlength="11" @focus="inputFocus('phone')" @blur="inputBlur('phone')" class="in" />
        <span class="bar"></span>
      </div>
      <div class="input">
        <label class="label" @click="inputFocus('code')" :class="{isFocus: isFocusCode || loginForm.password}">密码</label>
        <input type="password" ref="focusCode" v-model="loginForm.password" @keyup.13="submitLogin"  @focus="inputFocus('code')" @blur="inputBlur('code')" class="in" />
        <span class="bar"></span>
      </div>
    </div>
    <!-- <div class="checkbox">
      <el-checkbox v-model="checked">下次自动登录</el-checkbox>
    </div> -->
    <div class="saveBtn" @click="submitLogin" :class="{btnActive: isBtnActive}">{{isLoading ? '登录中' : '登 录'}}<div class="dotting" v-if="isLoading"><div class="dot"><span></span><span></span><span></span></div></div></div>
    <div class="copyright"><span>©2016-2018</span>成都市云智合一科技有限公司</div>
  </div>
</div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
      Loading: false,
      loginForm: {
        username: '',
        password: ''
      },
      checked: false,
      isLoading: false,
      count: '',
      timer: null,
      isFocusCode: false,
      isFocusPhone: false
    };
  },
  computed: {
    isBtnActive() {
      var _phone = this.loginForm.username + '';
      var _code = this.loginForm.password + '';
      return _phone && _code;
    }
  },
  created() {
  },
  mounted() {
    // this.$refs.focusCode.focus()
  },
  methods: {
    submitLogin() {
      if (this.isLoading || !this.isBtnActive) {
        return;
      }
      var _username = this.loginForm.username;
      var _password = this.loginForm.password;
      if (!_username) {
        this.$message.error('帐号不能为空');
        return;
      }
      if (!_password) {
        this.$message.error('密码不能为空');
        return;
      }
      this.isLoading = true;
      this.$store.dispatch('Login', this.loginForm).then((res) => {
        this.loading = false;
        this.$message({ message: '登录成功！', type: 'success' });
        this.$router.push({ path: '/buyphone' });
      }).catch(() => {
        this.loading = false;
      });
    },
    inputFun() {
      this.disable = !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phone)); ;
    },
    inputFocus(value) {
      if (value === 'code') {
        this.isFocusCode = true;
        this.$refs.focusCode.focus();
      }
      if (value === 'phone') {
        this.isFocusPhone = true;
        this.$refs.focusPhone.focus();
      }
    },
    inputBlur(value) {
      if (value === 'code') {
        this.isFocusCode = false;
      }
      if (value === 'phone') {
        this.isFocusPhone = false;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.login-box{
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: linear-gradient(180deg, #272A3E 0%, #252733 97%);
  height: 100%;
}
.login{
  width: 426px;
  padding: 46px 53px;
  background: #FFFFFF;
  border: 1px solid #C7C7C7;
  // box-shadow: 0 0 20px 0 rgba(0,0,0,0.34);
  border-radius: 4px;
  &::before{
    content: '';
    display: block;
    height: .88rem;
  }
  .logo{
    height: 36px;
    padding-left: 65px;
    font-size: 18px;
    color: #252733;
    line-height: 36px;
    letter-spacing: 1px;
    font-weight: 700;
    position: relative;
    &::before{
      content: '';
      display: block;
      position: absolute;
      left:0;
      top:0;
      width: 45px;
      bottom:0;
      background-image: url('/static/images/logo.png');
      background-repeat: no-repeat;
      background-size: contain;
      background-position: center center;
      border-radius: 10px;
    }
  }
  .loginName{
    font-size:32px;
    color:#203950;
    padding:22px 0 0;
  }
  .login-from{
    .input{
      padding: 30px 0 0;
      position: relative;
      &::before{
        content: "";
        pointer-events: none; /* 防止点击触发 */
        box-sizing: border-box;
        position: absolute;
        width: 200%;
        height: 200%;
        left: 0;
        top: 0;
        display: block;
        border-bottom:1px solid #cbcdd8;
        transform:scale(0.5);
        transform-origin: 0 0;
      }
      .in{
        padding: 12px 0;
        color:#333;
        font-size:15px;
        width: 100%;
      }
      .bar{
        position: relative;
        display: block;
        &::before,&::after{
          content: '';
          height: 1px;
          width: 0;
          bottom: -1px;
          position: absolute;
          background-color: #409eff;
          transition: 0.2s ease all;
          -moz-transition: 0.2s ease all;
          -webkit-transition: 0.2s ease all;
        }
        &::before{
          left:50%;
        }
        &::after{
          right:50%;
        }
      }
      .in:focus ~ .bar:before,
      .in:focus ~ .bar:after {
        width: 50%;
      }

      .label{
        display: block;
        position: absolute;
        top:40px;
        left:0;
        transition: all ease-in .2s;
        font-size:15px;
        color: #BFBFBF;
      }
      .label.isFocus{
        top:20px;
        font-size:12px;
      }
      .in::placeholder{
        color:#BFBFBF;
        font-size:15px;
      }
      .code{
        position: absolute;
        right: 0;
        display: block;
        width:150px;
        color:#409eff;
        bottom:10px;
        text-align: right;
      }
      .code.disable{
        color:#999;
      }
    }
  }
  .saveBtn{
    box-shadow: 0 0 .08rem 0 rgba(197,197,197,0.26);
    background: #999;
    border-radius: 2px;
    color:#fff;
    text-align: center;
    line-height: 48px;
    font-size:16px;
    cursor: pointer;
    margin:44px 0 0 0;
  }
  .saveBtn.btnActive{
    background: #409eff;
    cursor: pointer;
    box-shadow: 0 0 .08rem 0 rgba(68,111,255,0.26);
  }
  .checkbox{
    padding: 30px 0 0;
    text-align: right;
    .el-checkbox__label{
       color: #3A475A;
    }
  }
  .copyright{
    font-size:12px;
    color: #a2a2a6;
    position: relative;
    text-align: center;
    top:75px;
    span{
      color: #eee;
      padding-right: 10px;
    }
  }
  .dotting {
    display: inline-block;
    position: relative;
    vertical-align: middle;
    margin-left:4px;
    .dot{
      text-indent: -46px;
      width:25px;
      overflow: hidden;
      -webkit-animation: dot 2.5s infinite step-start both;
      animation: dot 2.5s infinite step-start both;
      span{
        position: relative;
        display: inline-block;
        width:8px;
        &:before {
          content: '';
          display: block;
          width:3px;
          vertical-align: middle;
          height: 3px;
          background-color: #fff;
          border-radius: 3px;
          position: absolute;
          overflow: hidden;
          top:-6px;
          left:1px;
        }
      }
    }
  }
}
  @keyframes dot {
      25% {
        text-indent: -30px;
      }
      50% {
        text-indent: -14px;
      }
      75% {
        text-indent: 1px;
      }
  }
</style>

